function YYYYMMDDstart()
{
    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    //先给年下拉框赋内容
    var y  = new Date().getFullYear();
    for (var i = (y-120); i < (y+30); i++) //以今年为准，前30年，后30年
        document.reg_testdate.YYYY.options.add(new Option(" "+ i, i));

    //赋月份的下拉框
    for (var i = 1; i < 13; i++)
        document.reg_testdate.MM.options.add(new Option(" " + i, i));

    document.reg_testdate.YYYY.value = y;
    document.reg_testdate.MM.value = new Date().getMonth() + 1;
    var n = MonHead[new Date().getMonth()];
    if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;
    writeDay(n); //赋日期下拉框Author:meizz
    document.reg_testdate.DD.value = new Date().getDate();
}
if(document.attachEvent)
    window.attachEvent("onload", YYYYMMDDstart);
else
    window.addEventListener('load', YYYYMMDDstart, false);
function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年)
{
    var MMvalue = document.reg_testdate.MM.options[document.reg_testdate.MM.selectedIndex].value;
    if (MMvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}
    var n = MonHead[MMvalue - 1];
    if (MMvalue ==2 && IsPinYear(str)) n++;
    writeDay(n)
}
function MMDD(str)   //月发生变化时日期联动
{
    var YYYYvalue = document.reg_testdate.YYYY.options[document.reg_testdate.YYYY.selectedIndex].value;
    if (YYYYvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}
    var n = MonHead[str - 1];
    if (str ==2 && IsPinYear(YYYYvalue)) n++;
    writeDay(n)
}
function writeDay(n)   //据条件写日期的下拉框
{
    var e = document.reg_testdate.DD; optionsClear(e);
    for (var i=1; i<(n+1); i++)
        e.options.add(new Option(" "+ i, i));
}
function IsPinYear(year)//判断是否闰平年
{     return(0 == year%4 && (year%100 !=0 || year%400 == 0));}
function optionsClear(e)
{
    e.options.length = 1;
}
var f2=0;
function changeBirth(){
    var select1=document.getElementById("year");
    var select2=document.getElementById("month");
    var select3=document.getElementById("day");
    var index1=select1.selectedIndex;
    var index2=select2.selectedIndex;
    var index3=select3.selectedIndex;
    var year=select1.options[index1].text;
    var month=select2.options[index2].text;
    var day=select3.options[index3].text;
    var birth=year+"/"+month+"/"+day;
    var sex=1;
    var phone=document.getElementById("self_phoneNum").innerText;
    var email=document.getElementById("self_email").innerText;
    if(f2==0){
        document.getElementById("birth_change").style.display="block";
        document.getElementById("change_birth_return").style.display="block";
        document.getElementById("change_birth").value="确认修改";
        f2=1;
    }
    else{
        if (document.getElementById("man").checked==true){
            sex=1;
        }
        else{
            sex=2;
        }
        $.ajax({
            type:'get',
            async:true,
            dataType:'json',
            url:'/update/userInfo' ,//接口
            data:{"birthday":birth,"sex":sex,"phone":phone,"email":email},
            success:function (data) {
                if(data.result==1)//与返回值比较，判断
                {
                    alert('修改成功！');
                    document.getElementById("birth_change").style.display="none";
                    document.getElementById("change_birth").value="修改生日";
                    document.getElementById("change_birth_return").style.display="none";
                    document.getElementById("self_birth").innerText=year+"/"+month+"/"+day;
                    document.getElementById("self_birth").style.fontWeight="bold";
                }else{
                    alert('修改失败！请仔细核实！')
                }
                // $('#name').empty();
                // var html ='';
                // $.each(data,function(nameIndex,name){
                //     html +='<tr><td>' + name['realName'] + '</td><td >' + name['idNumber'] + '</td></tr>';
                // });
                // $('#name').html(html);
            }
        });
        f2=0;
    }
}
function changeBirth_return(){
    document.getElementById("birth_change").style.display="none";
    document.getElementById("change_birth").value="修改生日";
    document.getElementById("change_birth_return").style.display="none";
    f2=0;
}
var f3=0;
function changeSex(){
    var select1=document.getElementById("year");
    var select2=document.getElementById("month");
    var select3=document.getElementById("day");
    var index1=select1.selectedIndex;
    var index2=select2.selectedIndex;
    var index3=select3.selectedIndex;
    var year=select1.options[index1].text;
    var month=select2.options[index2].text;
    var day=select3.options[index3].text;
    var birth=year+"/"+month+"/"+day;
    var sex=1;
    var phone=document.getElementById("self_phoneNum").innerText;
    var email=document.getElementById("self_email").innerText;
    if(f3==0){
        document.getElementById("sex_div").style.display="block";
        document.getElementById("change_sex").value="确认修改";
        document.getElementById("change_sex_return").style.display="block";
        f3=1;
    }
    else{
        if (document.getElementById("man").checked==true){
            sex=1;
        }
        else{
            sex=2;
        }
        $.ajax({
            type:'get',
            async:true,
            dataType:'json',
            url:'/update/userInfo' ,//接口
            data:{"birthday":birth,"sex":sex,"phone":phone,"email":email},
            success:function (data) {
                if(data.result==1)//与返回值比较，判断
                {
                    alert('修改成功！');
                    document.getElementById("sex_div").style.display="none";
                    document.getElementById("change_sex").value="修改性别";
                    document.getElementById("change_sex_return").style.display="none";
                    if (document.getElementById("man").checked==true){
                        document.getElementById("self_sex").innerText="男";
                        document.getElementById("self_sex").style.fontWeight="bold";
                    }
                    else{
                        document.getElementById("self_sex").innerText="女";
                        document.getElementById("self_sex").style.fontWeight="bold";
                    }
                }else{
                    alert('修改失败！请仔细核实！')
                }
                // $('#name').empty();
                // var html ='';
                // $.each(data,function(nameIndex,name){
                //     html +='<tr><td>' + name['realName'] + '</td><td >' + name['idNumber'] + '</td></tr>';
                // });
                // $('#name').html(html);
            }
        });
        f3=0;
    }
}
function changeSex_return(){
    document.getElementById("sex_div").style.display="none";
    document.getElementById("change_sex").value="修改性别";
    document.getElementById("change_sex_return").style.display="none";
    f3=0;
}
var f6=0;
function changePhone(){
    var select1=document.getElementById("year");
    var select2=document.getElementById("month");
    var select3=document.getElementById("day");
    var index1=select1.selectedIndex;
    var index2=select2.selectedIndex;
    var index3=select3.selectedIndex;
    var year=select1.options[index1].text;
    var month=select2.options[index2].text;
    var day=select3.options[index3].text;
    var birth=year+"/"+month+"/"+day;
    var sex=1;
    var phone=document.getElementById("phone_input").value;
    var email=document.getElementById("self_email").innerText;
    if(f6==0){
        document.getElementById("phone_input").style.display="block";
        document.getElementById("change_phone").value="确认修改";
        document.getElementById("change_phone_return").style.display="block";
        f6=1;
    }else{
        if (document.getElementById("man").checked==true){
            sex=1;
        }
        else{
            sex=2;
        }
        phone=document.getElementById("phone_input").value;
        if(phone.length!=11){
            alert("手机号不合法！")
        }
        else{
            $.ajax({
                type:'get',
                async:true,
                dataType:'json',
                url:'/update/userInfo' ,//接口
                data:{"birthday":birth,"sex":sex,"phone":phone,"email":email},
                success:function (data) {
                    if(data.result==1)//与返回值比较，判断
                    {
                        alert('修改成功！');
                        document.getElementById("phone_input").style.display="none";
                        document.getElementById("change_phone").value="修改手机号";
                        document.getElementById("change_phone_return").style.display="none";
                        document.getElementById("self_phoneNum").innerText=phone;
                        document.getElementById("self_phoneNum").style.fontWeight="bold";
                    }else{
                        alert('修改失败！请仔细核实！')
                    }
                    // $('#name').empty();
                    // var html ='';
                    // $.each(data,function(nameIndex,name){
                    //     html +='<tr><td>' + name['realName'] + '</td><td >' + name['idNumber'] + '</td></tr>';
                    // });
                    // $('#name').html(html);
                }
            });
        }
        f6=0;
    }
}
function changePhone_return(){
    document.getElementById("phone_input").style.display="none";
    document.getElementById("change_phone").value="修改手机号";
    document.getElementById("change_phone_return").style.display="none";
    f6=0;
}
var f4=0;
function changeEmail(){
    var select1=document.getElementById("year");
    var select2=document.getElementById("month");
    var select3=document.getElementById("day");
    var index1=select1.selectedIndex;
    var index2=select2.selectedIndex;
    var index3=select3.selectedIndex;
    var year=select1.options[index1].text;
    var month=select2.options[index2].text;
    var day=select3.options[index3].text;
    var birth=year+"/"+month+"/"+day;
    var sex=1;
    var phone=document.getElementById("self_phoneNum").innerText;
    var email=document.getElementById("email_input").value;
    if(f4==0){
        document.getElementById("email_input").style.display="block";
        document.getElementById("change_email").value="确认修改";
        document.getElementById("change_email_return").style.display="block";
        f4=1;
    }
    else{
        if (document.getElementById("man").checked==true){
            sex=1;
        }
        else{
            sex=2;
        }
        email=document.getElementById("email_input").value;
        if(email.length>20||email.length<=10){
            alert("输入不合法")
        }
        else{
            $.ajax({
                type:'get',
                async:true,
                dataType:'json',
                url:'/update/userInfo' ,//接口
                data:{"birthday":birth,"sex":sex,"phone":phone,"email":email},
                success:function (data) {
                    if(data.result==1)//与返回值比较，判断
                    {
                        alert('修改成功！');
                        document.getElementById("email_input").style.display="none";
                        document.getElementById("change_email").value="修改邮箱";
                        document.getElementById("change_email_return").style.display="none";
                        document.getElementById("self_email").innerText=email;
                        document.getElementById("self_email").style.fontWeight="bold";
                    }else{
                        alert('修改失败！请仔细核实！')
                    }
                    // $('#name').empty();
                    // var html ='';
                    // $.each(data,function(nameIndex,name){
                    //     html +='<tr><td>' + name['realName'] + '</td><td >' + name['idNumber'] + '</td></tr>';
                    // });
                    // $('#name').html(html);
                }
            });
        }
        f4=0;
    }
}
function changeEmail_return(){
    document.getElementById("email_input").style.display="none";
    document.getElementById("change_email").value="修改邮箱";
    document.getElementById("change_email_return").style.display="none";
    f4=0;
}
var f5=0;
function Real_authentication() {
    if(f5==0){
        document.getElementById("Real_name_authentication_div").style.display="block";
        f5=1;
    }
    else{
        document.getElementById("Real_name_authentication_div").style.display="none";
        f5=0;
    }
}
function submit_data(){
    var name=document.getElementById("name_authentication").value;
    var sex=document.getElementById("sex_authentication").value;
    var id=document.getElementById("id_authentication").value;
    if(name.length>5||name.length<2){
        alert("用户名不合法！")
    }
    else if(sex!="男"&&sex!="女"){
        alert("性别不合法！")
    }
    else if(id.length!=18){
        alert("身份证不合法！")
    }
    else{
        document.getElementById("Real_name_authentication_div").style.display="none";
        document.getElementById("Real_name_authentication").style.display="none";
    }
    $.ajax({
        type:'get',
        async:true,
        dataType:'json',
        url:'/certificates' ,//接口
        data:{"name":name,"sex":sex,"id":id},
        success:function (data) {
            if(data.result==1)//与返回值比较，判断
            {
                alert('实名认证成功！');
                window.location.href='Self_Information.html';
            }else{
                alert('认证失败！请仔细核实！')
            }
            // $('#name').empty();
            // var html ='';
            // $.each(data,function(nameIndex,name){
            //     html +='<tr><td>' + name['realName'] + '</td><td >' + name['idNumber'] + '</td></tr>';
            // });
            // $('#name').html(html);
        }
    });
}
function change_password() {
    window.location.href="Change_Password1.html";
}
function file_upload() {
    document.getElementById("upload").click();
    document.getElementById("bookUpper").style.display="block";
}
